<template>
  <div class="item-wrapper">
    <div
      class="item"
      @click="playerItem(item, index)"
      v-for="(item, index) of songlists"
      :key="item.id"
    >
      <h2 class="number colorOp8">{{index + 1}}</h2>
      <div class="pic">
        <img :src="item.al.picUrl" />
      </div>
      <div class="txt">
        <h2 class="name">{{item.name}}</h2>
        <div class="author">
          <!-- <b v-if="item.no === 0">vip</b> -->
          <span class="author-item" v-for="(author, index) of item.ar" :key="index">{{author.name}}</span>
          - {{item.al.name}}
        </div>
      </div>
      <div class="iconfont nicegengduo more"></div>
    </div>
  </div>
</template>

<script>
export default {
  props: {
    songlists: {
      type: Array,
      default: () => []
    }
  },
  methods: {
    // 点击播放歌曲
    async playerItem (item, index) {
      try {
        let res = await this.$api.getSongUrl(item.id)
        let url = res.data[0].url
        if (url) {
          this.$emit('playerSelect', item, index, url)
        } else {
          this.$toast({
            message: '可能要vip，换一首吧'
          })
        }
      } catch (error) {
        console.log(error)
      }
    }
  }
}
</script>

<style lang="stylus" scoped>
.item-wrapper {
  .item {
    width: 100%;
    height: 0.75rem;
    display: flex;
    margin-bottom: 0.35rem;
    align-items: center;

    .number {
      font-size: 0.3rem;
      margin-right: 0.25rem;
    }

    .pic {
      width: 0.75rem;
      height: 0.75rem;
      border-radius: 0.08rem;
      margin-right: 0.2rem;

      img {
        width: 0.75rem;
        height: 0.75rem;
        border-radius: 0.08rem;
      }
    }

    .txt {
      display: flex;
      flex-direction: column;
      align-items: flex-start;
      justify-content: center;
      flex: 1;
      width: 60%;

      .name {
        font-size: 0.28rem;
        color: rgba(255, 255, 255, 1);
        margin-bottom: 0.13rem;
        width: 90%;
        white-space: nowrap;
        text-overflow: ellipsis;
        -o-text-overflow: ellipsis;
        overflow: hidden;
      }

      .author {
        font-size: 0.24rem;
        color: rgba(255, 255, 255, 0.6);
        width: 100%;
        white-space: nowrap;
        text-overflow: ellipsis;
        -o-text-overflow: ellipsis;
        overflow: hidden;

        b {
          border: 1px solid #ff5b73;
          border-radius: 0.04rem;
          padding: 0 0.05rem;
          transform: scale(0.7);
          display: inline-block;
          color: #ff5b73;
        }
        span {
          &:after {
            content: '/';
            margin: 0 0.06rem;
          }

          &:last-child:after {
            content: '';
          }
        }
      }
    }

    .more {
      color: rgba(255, 255, 255, 0.8);
      font-size: 0.4rem;
    }
  }
}
</style>
